package oj;

public class LC203 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyHead=new ListNode(-1);
        dummyHead.next=head;
        ListNode prev=dummyHead;
        while(prev.next!=null){
            if(prev.next.val==val){
                ListNode node=prev.next;
                prev.next=node.next;
                node.next=null;
            }else {
                prev = prev.next;
            }
        }
        return dummyHead.next;
    }
}
